package com.chuangjiangx.member.stored.ddd.domain.model;

import java.util.Objects;

/**
 * @author cj-ch
 * @date 2018/4/4 下午6:52
 */
public enum  MbrOrderStatus {
//    NULL("无", -1),
    NOT_PAID("未支付", 0),
    PAID("支付成功", 1),
    CANCELLED("已撤销", 2),
    REFUNDED("已全额退款", 3),
    FAILED("支付失败", 4),
    PARTIAL_REFUNDED("部分退款", 5),
    CLOSED("已关闭", 6),
//    FREEZE("冻结中", 7),
//    REFUNDPROCESSING("退款中", 8),
//    REFUNDFILED("退款失败", 9);
    ;
    public final String name;
    public final Integer value;

    MbrOrderStatus(String name, Integer value) {
        this.name = name;
        this.value = value;
    }

    public static final MbrOrderStatus of(Integer value){
        for(MbrOrderStatus status : MbrOrderStatus.values()){
            if(Objects.equals(status.value,value)){
                return status;
            }
        }
        return null;
    }

    public static final boolean canRefund(MbrOrderStatus status){
        if(status == null){
            return false;
        }
        switch (status){
            case PAID:
            case PARTIAL_REFUNDED:
                return true;
            default:
                return false;
        }
    }
}
